package com.jrx.anytxn.customer.plugins;
import java.util.List;


import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.update.Update;

class SqlParserInfo {
	private String tableName;
	private String schemaName;
	private Table table;
	private Expression whereExpression;
	private List<Column> columns;
	private List<Expression> expressions;

	public SqlParserInfo(String sql) throws JSQLParserException {

		Statement statement = CCJSqlParserUtil.parse(sql);
		
			Update updateStatement = (Update) statement;
			List<Table> updateTables = updateStatement.getTables();
			if(updateTables==null || updateTables.isEmpty()){
				return ;
			}
			this.columns = updateStatement.getColumns();
			this.table = updateTables.get(0);
			this.whereExpression = updateStatement.getWhere();
		    this.expressions=updateStatement.getExpressions();
		
		this.tableName = table.getName();
		this.schemaName = table.getSchemaName();
	}



	public String getTableName() {
		return tableName;
	}

	public void setTableName(String tableName) {
		this.tableName = tableName;
	}

	public String getSchemaName() {
		return schemaName;
	}

	public void setSchemaName(String schemaName) {
		this.schemaName = schemaName;
	}

	public Table getTable() {
		return table;
	}

	public void setTable(Table table) {
		this.table = table;
	}

	public Expression getWhereExpression() {
		return whereExpression;
	}

	public void setWhereExpression(Expression whereExpression) {
		this.whereExpression = whereExpression;
	}

	public List<Column> getColumns() {
		return columns;
	}

	public void setColumns(List<Column> columns) {
		this.columns = columns;
	}

	public List<Expression> getExpressions() {
		return expressions;
	}

	public void setExpressions(List<Expression> expressions) {
		this.expressions = expressions;
	}
}

